package com.markyao.controller.recos;

import com.markyao.recos.conf.RecosConfService;
import com.markyao.recos.heartBeat.RecosHeartBeatService;
import com.markyao.recos.regist.RecosRegistService;
import com.markyao.utils.EncoderUtils;
import com.markyao.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/recos/group")
public class RecosGroupRegistController {

    @Autowired
    RecosRegistService recosRegistService;
    @Autowired
    RecosHeartBeatService recosHeartBeatService;

    @GetMapping("/registAppName")
    public Result registAppName(@RequestParam("appName") String appName, HttpServletRequest request){
        return recosRegistService.registAppName(appName,request);
    }

    @GetMapping("registUrl")
    public Result registUrl(@RequestParam("appName") String appName,@RequestParam("url") String url) {
        String decodeUrl = EncoderUtils.decode(url);
        return recosRegistService.registUrl(appName,decodeUrl);
    }
    @GetMapping("registWeight")
    public Result registWeight(@RequestParam("appName")String appName,@RequestParam("weight") Integer weight){
        return recosRegistService.registWeight(appName,weight);
    }

    @GetMapping("registServer0")
    public Result registServer0(@RequestParam("appName")String appName,@RequestParam("interfaceNAME") String interfaceNAME
            ,@RequestParam("clazz") String clazz)  {
        return recosRegistService.registServer0(appName,interfaceNAME,clazz);
    }
    @GetMapping("registRefrence")
    public Result registRefrence(@RequestParam("appName")String appName
            ,@RequestParam("refrenceName") String refrenceName) {

        return recosRegistService.registRefrence(appName,refrenceName);
    }

    @GetMapping("registConnect")
    public Result registConnect(@RequestParam("appName")String appName,
                                @RequestParam("targetUrl") String targetUrl) {
        return recosRegistService.registConnect(appName,targetUrl);
    }

    @GetMapping("registAlive")
    public Result alive(@RequestParam("appName")String appName){
        return recosHeartBeatService.alive(appName);
    }
}
